﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace dianying
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public OleDbCommand sqlCommand1 = null;
        public OleDbConnection sqlConnection1 = new OleDbConnection("Data Source=qggdch.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;");
        // public OleDbConnection sqlConnection1 = null ;

        private string LocalIP = string.Empty;
        private string RemoteIP = string.Empty;
        private string LocalMAC = string.Empty;
        private void Form2_Load(object sender, EventArgs e)
        {
            var ipv4 = NetWork.GetLocalIpv4(out LocalMAC);
            var mac = NetWork.GetMACs(out LocalIP);

            textBox1.Text = mac[0].ToString();
            string rolename = null;

            try
            {

                sqlCommand1 = new OleDbCommand();
                sqlCommand1.Connection = sqlConnection1;
                // string sql="delete * from outinfo where OutID="+ds.Tables["out"].Rows[dataGrid1.CurrentCell.RowNumber][13].ToString().Trim()+"";
                sqlConnection1.Open();
                OleDbCommand cmd = new OleDbCommand("", sqlConnection1);
                string sql = "select urlname from urlinfo where url='通用解析30'";//+ password.Text.Trim() + "'";
                //   string 
                cmd.CommandText = sql;

                if (null != cmd.ExecuteScalar())
                {
                    rolename = cmd.ExecuteScalar().ToString();

                    textBox2.Text = rolename;
                }
                else
                {
                    textBox2.Text = "无授权";
                }

                sqlConnection1.Close();
            }
            catch (Exception)
            {

                MessageBox.Show("授权有问题，请联系技术吖柒");
            }



        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox2.Text))
            {
                intUrl(textBox2.Text.ToString().Trim());

            }
            else
            {
                MessageBox.Show("请填写正确授权");
            }

        }

        public string intUrl(string mac)
        {
            string rolename = null;
            try
            {
                sqlCommand1 = new OleDbCommand();
                sqlCommand1.Connection = sqlConnection1;
                // string sql="delete * from outinfo where OutID="+ds.Tables["out"].Rows[dataGrid1.CurrentCell.RowNumber][13].ToString().Trim()+"";
                sqlConnection1.Open();
                OleDbCommand cmd = new OleDbCommand("", sqlConnection1);
                string sqla = "select urlname from urlinfo where url='通用解析30' ";//+ password.Text.Trim() + "'";
                string sql = "update urlinfo set urlname='" + mac + "'" + "where url='通用解析30'";
                //  string sql="ALTER TABLE urlinfo"
                //   string 
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
                cmd.CommandText = sqla;
                rolename = cmd.ExecuteScalar().ToString();
                if (rolename == "D19E489C25E4555F63EE5FB9B5E1A94B")
                {
                    MessageBox.Show("请重新登陆,进入无敌状态");
                }
                else
                {
                    rolename = DESEncrypt.Decrypt(rolename);
                    rolename = DESEncrypt.Decrypt(rolename);
                    rolename = DESEncrypt.Decrypt(rolename);
                    List<string> maca = NetWork.GetMACs(out LocalIP);
                    string getmac = maca[0].ToString();
                    if (rolename == getmac)
                    {
                        MessageBox.Show("授权中请重新登陆");
                    }
                }
            
                sqlConnection1.Close();
            }
            catch (Exception)
            {

                MessageBox.Show("授权有问题，请联系技术吖柒");
            }

            return rolename;
        }
    }
}
